<?php
/**
 * @package Sj Vm Extra Slider responsive
 * @version 2.5
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2013 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 * 
 */
    defined('_JEXEC') or die;
	
	JHtml::script('modules/mod_sj_vm_extraslider_res/assets/js/jcarousel.js');
	JHtml::stylesheet('templates/' . JFactory::getApplication()->getTemplate().'/html/mod_sj_vm_extraslider_res/vmextraslider.css');
	JHtml::stylesheet('modules/mod_sj_vm_extraslider_res/assets/css/css3.css');
	
    $vm_currency_display = &CurrencyDisplay::getInstance();
    $image_items_config = array(
    		'output_width'  => $params->get('item_image_width'),
    		'output_height' => $params->get('item_image_height'),
    		'function'		=> $params->get('item_image_function'),
    		'background'	=> $params->get('item_image_background')
    );    
    $options=$params->toObject();
	$count_item = count($items);
	$item_of_page = $options->num_rows * $options->num_cols;
	$suffix = rand().time();
	$tag_id = 'sjextraslider_'.$suffix;	
	   
	if(!empty($items)){?>
    <div id="<?php echo $tag_id;?>" class="sj-extraslider <?php if( $options->effect == 'slide' ){ echo $options->effect;}?> preset02-<?php echo $options->num_cols; ?>" data-pause='hover'>
		<?php if(!empty($options->pretext)) { ?>
			<div class="pre-text"><?php echo $options->pretext; ?></div>
		<?php } ?> 
        <?php if($options->title_slider_display == 1){?>
            <div class="heading-title"><?php echo $options->title_slider;?></div><!--end heading-title-->
        <?php }?>		    
    	<div class="extraslider-control  <?php if( $options->button_page == 'under' ){echo 'button-type2';}?>">
		    <?php if( $options->button_page == 'top' ){?>
		    <ul class="nav-page">
		    <?php $j = 0;$page = 0;
		    	foreach ($items as $item){$j ++;
				$active_class = $page == 0 ? " active" : "";
		    		if( $j%$item_of_page == 1 || $item_of_page == 1 ){$page ++;?>
		    		<li class="page">
		    			<a class="button-page <?php if( $page==1 ){echo 'sel';}?>" href="<?php echo '#'.$tag_id;?>" data-jslide="<?php echo $page-1;?>"></a>
		    		</li>
	    		<?php }}?>
		    </ul>
		    <?php }?>
	    </div>
	    <div class="extraslider-inner">
	    <?php $count = 0; $i = 0; 
	    foreach($items as $item){$count ++; $i++;?>
            <?php if($count%$item_of_page == 1 || $item_of_page == 1){?>
            <div class="item <?php if($i==1){echo "active";}?>">
            <?php }?>
                <?php if($count%$options->num_cols == 1 || $options->num_cols == 1 ){?>
                <div class="line">
                <?php }?>  
                
				    <div class="item-wrap <?php echo $options->theme; if($count%$options->num_cols == 0 || $count== $count_item && $options->num_cols !=1){echo " last";}?> ">
						<div class="item-wrap-inner">
							<div class="item-image">
								<a href="<?php echo $item->link;?>" <?php echo YTools::parseTarget($options->item_link_target);?> >
									<span class="item-image">
										<span class="border-img"></span>
										<span class="zoom-img"></span>
										<img src="<?php echo YTools::resize($item->images, $image_items_config);?>" alt="<?php echo $item->product_name;?>" title="<?php echo $item->product_name;?>"/>
									</span>
								</a>
							</div>
						<?php if( $options->item_title_display == 1 || $options->item_desc_display == 1  || $options->item_price_display == 1 || $options->item_readmore_display == 1 ){?>
							<div class="item-info">
							<?php if( $options->item_title_display == 1 ){?>
								<div class="item-title">
									<a href="<?php echo $item->link;?>" <?php echo YTools::parseTarget($options->item_link_target);?>>
										<?php echo Ytools::truncate($item->product_name,$options->item_title_max_characs);?>
									</a>
								</div>
							<?php }?>
							<?php if( ($options->item_desc_display == 1 && !empty($item->product_s_desc)) || $options->item_price_display == 1 || $options->item_readmore_display == 1 ){?>
								<div class="item-content">
									<?php if( $options->item_desc_display == 1 ){?>
										<div class="item-description">
											<?php
												$desc = "";
												if(!empty($item->product_s_desc)){
													YTools::extractImages($item->product_s_desc);
													$desc = $item->product_s_desc;	
												}else{
													YTools::extractImages($item->product_desc);
													$desc = $item->product_desc;	
												}
												if ( (int)$params->get('item_description_striptags', 1) ){
													$keep_tags = $params->get('item_description_keeptags', '');
													$keep_tags = str_replace(array(' '), array(''), $keep_tags);
													$tmp_desc = strip_tags($desc ,$keep_tags );
													echo YTools::truncate($tmp_desc, (int)$params->get('item_desc_max_characs'));
												} else {
													echo YTools::truncate($desc, (int)$params->get('item_desc_max_characs'));
												}?>                                
										</div>
									<?php }?>
									
										<?php if($options->item_price_display == 1){ ?>
											<div class="item-price">
												<div class="PricesalesPrice">
													<?php	$currency = &CurrencyDisplay::getInstance();
														if ( !empty($item->prices['salesPrice']) ){
															echo 'Price: '.$currency->createPriceDiv('salesPrice', '', $item->prices);
														}
														if ( !empty($item->prices['salesPriceWithDiscount']) ){
															echo $currency->createPriceDiv('salesPriceWithDiscount', '', $item->prices, true);
														}
													?>
												</div>
											</div>
										<?php } ?>                             
									
									<div class="addtocard-readmore">
										<?php if( $options->item_readmore_display == 1 ){?>
											<div class="item-readmore">
												<a class="button1" href="<?php echo $item->link;?>" target = "<?php echo $options->item_link_target;?>">
													<?php echo $options->item_readmore_text;?>
												</a>                                
											</div> 
										<?php }?>
									
										
										<div class="addtocart-area">
											<form method="post" class="product js-recalculate" action="<?php echo JRoute::_ ('index.php'); ?>">
												<?php // Product custom_fields
												if (!empty($item->customfieldsCart)) {
													?>
													<div class="product-fields">
														<?php foreach ($item->customfieldsCart as $field) { ?>
														<div class="product-field product-field-type-<?php echo $field->field_type ?>">
															<span class="product-fields-title-wrapper"><span class="product-fields-title"><strong><?php echo JText::_ ($field->custom_title) ?></strong></span>
															<?php if ($field->custom_tip) {
															echo JHTML::tooltip ($field->custom_tip, JText::_ ($field->custom_title), 'tooltip.png');
														} ?></span>
															<span class="product-field-display"><?php echo $field->display ?></span>
										
															<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
														</div><br/>
														<?php
													}
														?>
													</div>
													<?php
												}
												/* Product custom Childs
													 * to display a simple link use $field->virtuemart_product_id as link to child product_id
													 * custom_value is relation value to child
													 */
										
												if (!empty($item->customsChilds)) {
													?>
													<div class="product-fields">
														<?php foreach ($item->customsChilds as $field) { ?>
														<div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
															<span class="product-fields-title"><strong><?php echo JText::_ ($field->field->custom_title) ?></strong></span>
															<span class="product-field-desc"><?php echo JText::_ ($field->field->custom_value) ?></span>
															<span class="product-field-display"><?php echo $field->display ?></span>
										
														</div><br/>
														<?php } ?>
													</div>
													<?php }
										
												if (!VmConfig::get('use_as_catalog', 0) and !empty($item->prices['salesPrice'])) {
												?>
										
												<div class="addtocart-bar">
										
													<?php // Display the quantity box
										
													$stockhandle = VmConfig::get ('stockhandle', 'none');
													if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($item->product_in_stock - $item->product_ordered) < 1) { ?>
														<a href="<?php echo JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $item->virtuemart_product_id); ?>" class="notify"><?php echo JText::_ ('COM_VIRTUEMART_CART_NOTIFY') ?></a>
													<?php } else { ?>
														<?php
														// Display the add to cart button
														?>
														<span class="addtocart-button">
															<?php echo shopFunctionsF::getAddToCartButton ($item->orderable); ?>
														</span>
													
													<?php } ?>
										
													<div class="clear"></div>
												</div>
												<?php }
												 // Display the add to cart button END  ?>
												 
												<input type="hidden" name="quantity[]" value="<?php if (isset($item->min_order_level) && (int)$item->min_order_level > 0) {
																echo $item->min_order_level;
															} else {
																echo '1';
															} ?>"/>
												<input type="hidden" class="pname" value="<?php echo htmlentities($item->product_name, ENT_QUOTES, 'utf-8') ?>"/>
												<input type="hidden" name="option" value="com_virtuemart"/>
												<input type="hidden" name="view" value="cart"/>
												<noscript><input type="hidden" name="task" value="add"/></noscript>
												<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $item->virtuemart_product_id ?>"/>
											</form>
										
											<div class="clear"></div>
										</div><!--end add to card-->
									
									
									</div>
								</div>
							<?php }?>
							</div>
						<?php }?>
						</div>
				    </div>                
                 
                <?php if($count%$options->num_cols == 0 || $count== $count_item){?>    
                </div><!--line-->
                <?php } ?>		    		
            <?php if(($count%$item_of_page == 0 || $count== $count_item)){?>    
            </div><!--end item--> 
            <?php }?>
	    <?php }?>
	    </div><!--end extraslider-inner -->
	    <?php if( $options->button_page == 'under' ){?>
	    <ul class="nav-page nav-under">
	    <?php $j = 0;$page = 0;
	    	foreach ($items as $item){$j ++;
			$active_class = $page == 0 ? " active" : "";
	    		if( $j%$item_of_page == 1 || $item_of_page == 1 ){$page ++;?>
	    		<li class="page">
	    			<a class="button-page <?php if( $page==1 ){echo 'sel';}?>" href="<?php echo '#'.$tag_id;?>" data-jslide="<?php echo $page-1;?>"></a>
	    		</li>
    		<?php }}?>
	    </ul>
	    <?php }?>	    
		<?php if(!empty($options->posttext)) {  ?>
			<div class="post-text"><?php echo $options->posttext; ?></div>
		<?php }?>
    </div>
<?php }else{ echo JText::_('Has no item to show!');}?>

<script>
//<![CDATA[    					
	jQuery(function($){
		$('#<?php echo $tag_id;?>').each(function(){
			var $this = $(this), options = options = !$this.data('modal') && $.extend({}, $this.data());
			$this.jcarousel(options);
			$this.bind('jslide', function(e){
				var index = $(this).find(e.relatedTarget).index();

				// process for nav
				$('[data-jslide]').each(function(){
					var $nav = $(this), $navData = $nav.data(), href, $target = $($nav.attr('data-target') || (href = $nav.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, ''));
					if ( !$target.is($this) ) return;
					if (typeof $navData.jslide == 'number' && $navData.jslide==index){
						$nav.addClass('sel');
					} else {
						$nav.removeClass('sel');
					}
				});
			});
		});
		return ;
	});
//]]>	
</script>

